'''
dionysus - a web based dialogue management framework
Copyright (C) 2011  Eugeniu Costetchi <eugeniu.costetchi (at) tudor.lu>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Created on Jan 4, 2011
'''

import logging
from time import strftime, gmtime
import sys
import traceback
from DialogueManager.utils.properties import LOG_FILENAME

logging.basicConfig(filename=LOG_FILENAME, level=logging.INFO)

def log_debug(message, exception=False):
    #in depth logging
    try:
        if exception:
            logging.error('['+str(strftime("%y/%m/%d %H:%M:%S",gmtime())) + ']' + message)
            type, value, tb = sys.exc_info()
            #logging.error('\n'.join(traceback.format_tb(tb)))
            logging.error (''+traceback.format_exc())
        else:
            logging.info('['+str(strftime("%y/%m/%d %H:%M:%S",gmtime())) + ']' + message)
    except:
        print 'Could not write the log file'
#print datetime.datetime.now()
#print datetime.datetime.today()
#print strftime("%y/%m/%d %H:%M:%S")

#try:
#    raise Exception('ababa')
#except Exception, e:
#    log_debug("cucu ru s", exception=True)